package com.gzhryc.net_marketing.cloud.goods.dao.db;

import com.gzhryc.common.config.DefaultEnum;
import com.gzhryc.common.data.ITreeEntity;
import com.gzhryc.jdbc.annotaion.Column;
import com.gzhryc.jdbc.annotaion.Id;
import com.gzhryc.jdbc.annotaion.Parent;
import com.gzhryc.jdbc.annotaion.Table;
import com.gzhryc.jdbc.models.LRTree;
import com.gzhryc.net_marketing.core.enums.EGoodsClassify;

import java.util.Date;
import java.util.List;

@Table(name="market_goods_type")
public class GoodsType extends LRTree<Long> implements ITreeEntity<GoodsType, Long> {

    private static final long serialVersionUID = 1L;

	@Id
    protected Long id;

    @Column(length = 32, notNull = true, note = "类型名称，一般为中文名称")
    protected String name;

    @Column(notNull = true, note = "类型代码，用于程序调用，一般为英文名称")
    protected String code;

    @Column(name="classify",notNull = true,defVal = "1",note = "商品类型，1：实物，2：虚拟")
    protected Integer classify;

    @Column
    protected Integer priority; // 优先级

    @Column
    protected Integer state;    //状态

    @Column(name = "root_id")
    protected Long rootId;

    @Column(name = "left_num")
    protected Long leftNum;

    @Column(name = "right_num")
    protected Long rightNum;

    @Column(name = "parent_id")
    protected Long parentId; // 父节点Id

    @Column(name = "update_date", note = "修改时间", autoUpdateTime = true)
    protected Date updateDate;

    @Column(name = "create_date")
    protected Date createDate;

    @Parent("name")
    protected String parentName;

    @Parent("code")
    protected String parentCode;

    protected List<GoodsType> children;

    @Override
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public Integer getClassify() {
        return classify;
    }

    public void setClassify(Integer classify) {
        this.classify = classify;
    }

    public Integer getPriority() {
        return priority;
    }

    public void setPriority(Integer priority) {
        this.priority = priority;
    }

    public Integer getState() {
        return state;
    }

    public void setState(Integer state) {
        this.state = state;
    }

    @Override
    public Long getRootId() {
        return rootId;
    }

    @Override
    public void setRootId(Long rootId) {
        this.rootId = rootId;
    }

    @Override
    public Long getLeftNum() {
        return leftNum;
    }

    @Override
    public void setLeftNum(Long leftNum) {
        this.leftNum = leftNum;
    }

    @Override
    public Long getRightNum() {
        return rightNum;
    }

    @Override
    public void setRightNum(Long rightNum) {
        this.rightNum = rightNum;
    }

    @Override
    public Long getParentId() {
        return parentId;
    }

    @Override
    public void setParentId(Long parentId) {
        this.parentId = parentId;
    }

    public Date getUpdateDate() {
        return updateDate;
    }

    public void setUpdateDate(Date updateDate) {
        this.updateDate = updateDate;
    }

    public Date getCreateDate() {
        return createDate;
    }

    public void setCreateDate(Date createDate) {
        this.createDate = createDate;
    }

    public String getParentName() {
        return parentName;
    }

    public void setParentName(String parentName) {
        this.parentName = parentName;
    }

    public String getParentCode() {
        return parentCode;
    }

    public void setParentCode(String parentCode) {
        this.parentCode = parentCode;
    }

    public boolean getIsLeaf() {
        if (this.leftNum != null && this.rightNum != null) {
            return !(this.rightNum - this.leftNum > 1);
        }
        return true;
    }

    public boolean getHaveChild() {
        return !this.getIsLeaf();
    }

    @Override
    public List<GoodsType> getChildren() {
        return this.children;
    }

    @Override
    public void setChildren(List<GoodsType> children) {
        this.children = children;
    }

    public String getStateName(){
        return DefaultEnum.Status.note(this.state);
    }

    public String getClassifyName(){
        return EGoodsClassify.note(this.classify);
    }
}
